home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / me_cd25.zip / MUTT2.ZIP / SHELL.MUT < prev    next >
Text File  |  1992-11-09  |  3KB  |  110 lines

  1. ;; shell.mut 
  2. ;; An attempt at a shell buffer using the compute server.
  3. ;; Note:  the shell is NOT interactive.
  4.  
  5. ;; C Durland 11/91    Public Domain
  6.  
  7. (include me2.h)
  8.  
  9. (const
  10.   SHELL-BUFFER-NAME    "*Shell*"
  11. )
  12.  
  13. (int shell-buffer shell-process-id output-mark)
  14. (bool shell-running command-running)
  15.  
  16. (defun
  17.   MAIN { (register-hook PROCESS-HOOK "process-shell-hook") }
  18.   shell-shock
  19.   {
  20.     (int wid)
  21.     (string command)
  22.  
  23.     (if (shell-running) { (msg "Got a shell already running!")(done) })
  24.  
  25.     (if (== -2 (shell-buffer (attached-buffer SHELL-BUFFER-NAME)))
  26.     (shell-buffer (create-buffer SHELL-BUFFER-NAME BFFoo)))
  27.  
  28.     (if (!= -2 (wid (buffer-displayed shell-buffer)))
  29.       (current-window wid)
  30.       {
  31.         (delete-other-windows)(split-window)
  32.     (current-window 0)        ;; move to top window
  33.       })
  34.  
  35.     (current-buffer shell-buffer TRUE) (clear-buffer)
  36.     (bind-local-key "shell-ret"    "C-M")
  37.  
  38.     (if (== 0 output-mark) (output-mark (create-mark TRUE)))
  39.  
  40.     (command-running FALSE)
  41.     (shell-running TRUE)
  42.     (major-mode "Waiting")
  43.  
  44.     (insert-text "> ^J")(update)
  45.   }
  46.   shell-ret
  47.   {
  48.     (int mark bag col)
  49.     (string command)
  50.  
  51.     (beginning-of-line)
  52. ; look for cd, pu and po
  53.  
  54.     (mark (create-mark))(set-mark)(end-of-line)
  55.     (bag (create-bag))(append-to-bag bag APPEND-REGION)
  56.  
  57.     (forward-line 1)
  58.     (if (not (EoB)) { (end-of-buffer)(insert-bag bag)(forward-line 1) })
  59.     (set-mark output-mark)
  60.  
  61.     (shell-process-id (create-process
  62.     (concat "/bin/sh -c " '"' (bag-to-string bag) '"')))
  63.  
  64.     (if (== -1 shell-process-id) (done))        ;; some kind of error
  65.  
  66.     (major-mode (concat "Running: " (bag-to-string bag)))
  67.     (command-running TRUE)
  68.   }
  69.   process-shell-hook (int pid event-type)(message)
  70.   {
  71.     (int wid1 wid2)
  72.  
  73.     (if (== PERROR event-type)
  74.     {
  75.       (if shell-running
  76.         { (current-buffer shell-buffer) (major-mode "Error") (update) })
  77.       (shell-running FALSE)
  78.       (done)
  79.     })
  80.     (if (not (shell-running)) (done))
  81.     (if (!= shell-process-id pid) (done))
  82.  
  83.     (current-buffer shell-buffer)(goto-mark output-mark)
  84.     (switch event-type
  85.       PROCESS-DONE
  86.       {
  87.     (command-running FALSE)
  88.     (major-mode (concat "Waiting"))
  89.     (insert-text "^J> ^J")
  90.       }
  91.       OUTPUT-STDOUT { (insert-text message) }
  92.       OUTPUT-STDERR { (insert-text message) }
  93.     )
  94.     (set-mark output-mark)
  95.  
  96.     (update)
  97.   }
  98. )
  99.  
  100. (defun
  101.   buffer-displayed (int buffer-id) HIDDEN
  102.   {
  103.     (int n)
  104.     (for (n 0) (< n (windows)) (+= n 1)
  105.     (if (== buffer-id (attached-buffer n)) { n (done) }))
  106.     -2            ;; buffer not displayed
  107.   }
  108. )
  109.  
  110.